home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Financial
/
USDebtWatch
/
Source
/
xdebt-xcerpt.c
< prev
Wrap
C/C++ Source or Header
|
1995-06-12
|
3KB
|
105 lines
/* most of this file is excerpted from Jamie Zawinski's xdebt program.
Jamie Zawinski is <jwz@lucid.com>. Public Domain.
Mods by Erik Sowa (sowa@netcom.com).
I have replaced the call to 'timelocal,' which I could not locate,
with a call to Oliver Laumann's tm_to_time, which I obtained from
Volume 4 of the comp.unix.sources archives.
More mods by sonroc@nemesis.zycad.com [a/k/a twk@zycad.com] to include
per-capita.
*/
#include <time.h>
#include <stdio.h>
extern time_t tm_to_time();
/* older debt estimate */
/* The US National Debt, and its rate of increase as of December 31, 1988
(in dollars per second) according to the 1989 Survey of Current Business.
. These values are floats because they're >42 bits.
*/
typedef double debt_t, pop_t;
#define SCB89DEBT 2707284000000.0
#define SCB89DELTA 7673.015
static struct tm scb89debt_tm = { 0, 0, 0, 31, 11, 88 }; /* Dec. 31, 1988 */
/* newer debt estimate */
/* The US National Debt, and its rate of increase as of June 30, 1992 */
/* (in $/second) based on numbers from the 5 July 1992 Albuquerque Journal */
/* .... thanks to Brooke King brooke@fuchsia.albuq.ingr.com */
#define AJ92DEBT 3965170506502.395 /* in dollars */
#define AJ92DELTA 14132.887 /* Dollars per second */
static struct tm aj92debt_tm = { 0, 0, 0, 30, 05, 92 };
/* The US Population, and its rate of increase, as of July 1, 1990 */
/* (in people/second) based on numbers from the CIA's World Factbook 1990 */
/* .... thanks to tom@genie.slhs.udel.edu */
#define POP 250410000.0 /* people */
#define POP_DELTA 0.0714151266 /* increase in people per second */
static struct tm pop_tm = { 0, 0, 0, 1, 6, 90 };
debt_t
national_scb89debt_at (now)
time_t now;
{
time_t debt_date = tm_to_time(&scb89debt_tm);
time_t seconds_since_then = now - debt_date;
debt_t delta_since_then = SCB89DELTA * seconds_since_then;
return SCB89DEBT + delta_since_then;
}
debt_t
national_aj92debt_at (now)
time_t now;
{
time_t debt_date = tm_to_time(&aj92debt_tm);
time_t seconds_since_then = now - debt_date;
debt_t delta_since_then = AJ92DELTA * seconds_since_then;
return AJ92DEBT + delta_since_then;
}
pop_t
national_pop_at (now)
time_t now;
{
time_t pop_date = tm_to_time(&pop_tm);
time_t seconds_since_then = now - pop_date;
pop_t delta_since_then = POP_DELTA * seconds_since_then;
return POP + delta_since_then;
}
extern char *index ();
void
debt_to_string (debt, s)
debt_t debt;
char *s;
{
int L, i = 0;
char buf [255];
char *b = buf;
sprintf (b, "%lf\0", debt);
b = index (b, '.') - 1;
L = b - buf;
s += L + (L / 3);
*(s+1) = 0;
i = -1;
while (1)
{
if (++i == 3) i = 0, *s-- = ',';
if (b < buf) return;
*s-- = *b--;
}
}